<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/header::commonlinks(~{::title},~{::link})">
    <meta charset="UTF-8">
    <title>更改密码</title>
    <link rel="stylesheet" th:href="@{/unauthorize/login.css}">
</head>
<body class="hold-transition sidebar-collapse layout-navbar-fixed layout-top-nav"style="height: 773px">
<div class="wrapper">

    <!-- Navbar -->
    <div th:include="~{common/header::topnavbar-md}"></div>
    <!-- /.navbar -->

    <!-- Main Sidebar Container -->

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">

        <!-- Main content -->
        <div class="content">
            <div class="stars-bg">
                <div id="stars"> </div>
                <canvas id="cvs"></canvas>
            <div class="container login-page" style="position: absolute;opacity: 0.9">
                <div class="login-box">

                    <!-- /.login-logo -->
                    <div class="card">
                        <div class="login-logo">
                            <a href="../../index2.html"><b>更改密码</b></a>
                        </div>
                        <div class="card-body login-card-body">
                            <p class="login-box-msg">您距新密码仅一步之遥，立即恢复密码。</p>

                            <form action="" method="" class="needs-validation validateForm" novalidate>
                                <input type="text" th:value="${uid}" name="uid" hidden>
                                <div class="input-group mb-3">
                                    <input type="password" class="form-control" name="password" placeholder="密码"
                                           required id="password1">
                                    <div class="input-group-append">
                                        <div class="input-group-text">
                                            <span class="fas fa-lock"></span>
                                        </div>
                                    </div>
                                    <div class="invalid-feedback equal-validate">
                                        密码不能为空
                                    </div>
                                </div>
                                <div class="input-group mb-3">
                                    <input type="password" class="form-control" placeholder=" 确认密码"
                                           name="confirmpassword" required id="password2">
                                    <div class="input-group-append">
                                        <div class="input-group-text">
                                            <span class="fas fa-lock"></span>
                                        </div>
                                    </div>
                                    <div class="invalid-feedback equal-validate">
                                        密码确认不能为空
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-12">
                                        <button type="submit"
                                                class="btn btn-primary btn-block update-password valid-button"> 更改密码
                                        </button>
                                    </div>
                                    <!-- /.col -->
                                </div>
                            </form>

                            <p class="mt-3 mb-1">
                                <a th:href="@{/unAuthorize/login}">登录</a>
                            </p>
                        </div>
                        <!-- /.login-card-body -->
                    </div>
                </div>
                <!-- /.login-box -->
                <!-- 右侧栏 -->
                <div th:include="~{common/header::rightaside}"></div>
                <!-- /右侧栏 -->
                <!-- 底部栏 -->
                <div style="width:70%" th:include="~{common/footer::footer}"></div>
                <!-- /底部栏 -->
                <!--    公有的js-->
                <div th:replace="common/header::commonjs(~{::script})">
                    <!--        私有的js-->
                    <script th:src="@{/admin/article/index.js}"></script>
                    <script th:src="@{/unauthorize/login.js}"></script>
                </div>
            </div><!-- /.container-fluid -->
            </div>
        </div>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->

</div>
<!-- ./wrapper -->
<script>

    // $(".update-password").off().on('click', function () {
    //     var uid = $("input[name='uid']").val();
    //     var password = $("input[name='password']").val();
    //     var confirmpassword = $("input[name='confirmpassword']").val();
    //     if (confirmpassword.length != 0 && password.length != 0) {
    //
    //         $.ajax({
    //                 url: '/unAuthorize/updatePassword?password=' + password + '&uid=' + uid,
    //                 type: 'get',
    //                 dataType: "json",
    //                 // async: true,
    //                 processData: false,   // 不处理发送的数据
    //                 contentType: false,   // 不设置Content-Type请求头
    //                 success:
    //                     function (res) {
    //                         if (res.code == 200) {
    //                             $.toast({
    //                                 title: '通知',
    //                                 subtitle: '5秒前',
    //                                 content: '修改密码成功',
    //                                 type: 'success',
    //                                 delay: 30000,
    //                                 img: {
    //                                     src: 'image.png',
    //                                     class: 'rounded',
    //                                     title: 'Thumbnail Title',
    //                                     alt: 'Alternative'
    //                                 },
    //                                 pause_on_hover: false
    //                             });
    //                             window.location.href = '/unAuthorize/index';
    //
    //
    //                         } else {
    //                             alert(res.msg)
    //                         }
    //                     }
    //             }
    //         )
    //
    //     }
    // })

    $('.validateForm').off().submit(function () {
        var uid = $("input[name='uid']").val();
        var password = $("input[name='password']").val();
        var confirmpassword = $("input[name='confirmpassword']").val();
        if (confirmpassword.length != 0 && password.length != 0) {
            var data = $('.validateForm').serialize();
            $.ajax({
                    url: '/unAuthorize/updatePassword?' + data,
                    type: 'post',
                    dataType: "json",
                    // contentType: 'application/json;charset=UTF-8',
                    // data: JSON.stringify(data),
                    // async: true,
                    processData: false,   // 不处理发送的数据
                    contentType: false,   // 不设置Content-Type请求头
                    success:
                        function (res) {
                            if (res.code == 200) {
                                $.toast({
                                    title: '通知',
                                    subtitle: '5秒前',
                                    content: '修改密码成功',
                                    type: 'success',
                                    delay: 30000,
                                    img: {
                                        src: 'image.png',
                                        class: 'rounded',
                                        title: 'Thumbnail Title',
                                        alt: 'Alternative'
                                    },
                                    pause_on_hover: false
                                });
                                window.location.href = '/unAuthorize/index';


                            } else {
                                $.toast({
                                    title: '通知',
                                    subtitle: '5秒前',
                                    content: res.msg,
                                    type: 'info',
                                    delay: 20000,

                                    pause_on_hover: false
                                });
                            }
                        }
                }
            )

        }
        return false;
    })
</script>
</body>
</html>